#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define STR_LEN 255

int countAnagrams(const char *, const char *); /* 统计变位词个数 */
int areAnagrams(const char *, const char *); /* 变位词判断 */

/* 辅助函数 */
int read_line(char *, int); /* 读入不超过指定长度的字符串 */
void lowcase(char *); /* 将字符串变为小写 */

int main()
{
	    char text[STR_LEN + 1] = {'\0'};
	        char word[STR_LEN + 1] = {'\0'};
		    int cnt = 0;

		        read_line(text, STR_LEN);
			    read_line(word, STR_LEN);

			        cnt = countAnagrams(text, word);

				    printf("The text is \"%s\".\n", text);
				        printf("The word is \"%s\".\n", word);
					    printf("The count of anagrams is %d.\n", cnt);

					        return 0;
}

/* 函数实现 */
/* 读入一行不超过指定长度的字符串 */
int read_line(char *str, int n)
{
	    int ch, i = 0;

	        /* 读入字符，直到遇到换行符 */
	        while ((ch = getchar()) != '\n' && ch != '\r' && ch!=EOF)
			    {
				            if(i < n) /* 最大字符数 */ 
						            { str[i++] = ch; }
					         }
		     str[i] = '\0'; /* 添加空字符'\0' */ 
		          return i; /* 返回读入的字符数 */ 
}






void lowcase(char*s)
        {
                int len =sizeof(s)-1;

                int i;

                for(i=0;i<=len;i++)
                {
                        if(s[i]>=65 && s[i]<=90)
                        {
                                s[i]+=32;
                        }

                }
        }
 int areAnagrams(const char*word1,const char *word2)
        {
		char word01[225]={'\0'};
		char word02[225]={'\0'};
		strcpy(word01,word1);
		strcpy(word02,word2);
                lowcase (word01);
                lowcase(word02);

                if(strcmp(word01,word02)==0)
                {
                        return 1;
                }
                        else return 0;

        }


int countAnagrams(const char *text,const char * word)
{

	int i, j,p, num =0;
	int len = strlen(word);
	char * word1=(char*)malloc(len+1);
	for(p=0;;p++)
	{
		if(text[p]=='\0') break;
	}
	
	for(i=0;i<p-len;i++)
	{
		for(j=0;j<len;j++)
		{
			word1[j]=text[i++];
		}


		if(areAnagrams(word1,word)==1)
		{
			num ++;
		}

	}

	return num;


}



